package work.linruchang.mybatisplussamplestest.config.mybatisplus;

import cn.hutool.core.date.DatePattern;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * 作用：
 *
 * @author LinRuChang
 * @version 1.0
 * @date 2022/06/13
 * @since 1.8
 **/
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "createTime", String.class, DatePattern.NORM_DATETIME_FORMATTER.format(LocalDateTime.now()));
        this.strictInsertFill(metaObject, "updateTime", String.class, DatePattern.NORM_DATETIME_FORMATTER.format(LocalDateTime.now()));
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject, "updateTime", String.class, DatePattern.NORM_DATETIME_FORMATTER.format(LocalDateTime.now()));
    }
}
